package com.mingtu.jgspatrol.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.common.utils.ConvertLatlng;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.bean.VideoListBean2;

public class MonitoringDequiAdapter extends BaseQuickAdapter<VideoListBean2.PageBean.ListBean, BaseViewHolder> {

    private Context context;

    public MonitoringDequiAdapter(Context context) {
        super(R.layout.item_monitoring_dequi);
        this.context = context;
    }


    @Override
    protected void convert(@NonNull BaseViewHolder helper, VideoListBean2.PageBean.ListBean listBean) {
        String cameraName = listBean.getName();
        String deptName = listBean.getDeptName();
        String address = listBean.getAddress();
        String latitude = listBean.getLat();
        String longitude = listBean.getLng();
        String status = listBean.getStatus();
        TextView tvAddress = helper.getView(R.id.tv_address);

        helper.setText(R.id.tv_name, cameraName);
        helper.setText(R.id.tv_depart, "所属部门：" + deptName);
        if (!StringUtils.isEmpty(address)) {
            tvAddress.setText("设备位置：" + address);
            tvAddress.setVisibility(View.VISIBLE);
        } else {
            tvAddress.setVisibility(View.GONE);
        }

        if (!StringUtils.isEmpty(latitude) && !StringUtils.isEmpty(longitude)) {
            double lng = Double.parseDouble(longitude);
            double lat = Double.parseDouble(latitude);
            String myLng = ConvertLatlng.getInstance().convertToSexagesimal(lng);
            String myLat = ConvertLatlng.getInstance().convertToSexagesimal(lat);
            helper.setText(R.id.tv_lat_lng, "经纬度：" + myLng + "," + myLat);
            helper.setGone(R.id.layout_nav, true);
        } else {
            helper.setGone(R.id.layout_nav, false);
        }


        if (!StringUtils.isEmpty(status)) {
            if (status.equals("1")) {
                //离线
                helper.setText(R.id.tv_offline, "离线");
                helper.setTextColor(R.id.tv_offline, context.getResources().getColor(R.color.bg_color_fb3));
                helper.getView(R.id.tv_offline).setBackgroundResource(R.drawable.shape_dequi_status2);
            } else if (status.equals("0")) {
                //在线
                helper.setText(R.id.tv_offline, "在线");
                helper.setTextColor(R.id.tv_offline, context.getResources().getColor(R.color.colorPrimary));
                helper.getView(R.id.tv_offline).setBackgroundResource(R.drawable.shape_dequi_status1);
            }
        }
        helper.addOnClickListener(R.id.layout_nav);
    }
}
